﻿@using RooHui.Infrastructure.Entities.Entity;
@using RooHui.Infrastructure.Entities.Enum
@using RooHui.Tool
@{
    ViewBag.Title = "ProjectAudit";
    Layout = "~/Views/Shared/_Base.cshtml";
    List<ProcessStepDoing> processStepList = ViewBag.processStepList;
    Project project = ViewBag.project;
    ProcessDoing processDoing = ViewBag.processDoing;
    List<ProcessDoingHistory> processDoingHistoryList = ViewBag.processDoingHistoryList;
    List<RepaymentPlan> repaymentPlanList = ViewBag.repaymentPlanList;
    Policy policy = project.PolicyList.FirstOrDefault(c => !c.IsAttach);
    int cycleAmount = policy.CycleAmount;
    if (policy.CycleAmount == 0)
    {
        cycleAmount = project.CycleAmount;
    }
    decimal monthcount = 0m;
    if (policy.DurationType == DurationType.ByDay)
    {
        monthcount = Math.Round((((decimal)(cycleAmount * policy.Duration)) / 365) * 12, 2, MidpointRounding.AwayFromZero);
    }
    else
    {
        monthcount = cycleAmount * policy.Duration;
    }

    decimal reward = repaymentPlanList.Where(c => c.Policy.IsAttach).ToList().Sum(c => c.RepaymentInterest);
    decimal profits = Math.Round((project.Financing * (project.OriginalRate - project.GuaranteeRate - policy.Rate) / 100) * (monthcount / 12), 2, MidpointRounding.AwayFromZero);
    decimal lastprofits = profits - reward;
}
@section head{
    <script type="text/javascript">
        $(function () {

            $("#projecttab").ligerTab({ contextmenu: false });
            $("#btnSave").click(function () {
                $.ligerDialog.waitting("处理中,请稍后...");
                $.ajax({
                    url: "/ProjectAudit/ProjectAuditDo",
                    data: "projectID=" + $("#projectID").val() + "&processStepDoingID=" + $('#selProcessStep').val()
                    + "&doContent=" + $("#txtAuditContent").val(),
                    type: "post",
                    success: function (result) {
                        $.ligerDialog.closeWaitting();
                        //写提交ajax操作
                        if (result == "1") {
                            $.ligerDialog.success("审核成功。");
                            location.href = decodeURIComponent("/ProjectAudit/Index");
                        }
                        else {

                            $.ligerDialog.error("审核失败");

                        }

                    }
                });
            });
            $("#btnCancel").click(function () { location.href = decodeURIComponent("/ProjectAudit/Index"); });

            $("#selProcessStep").ligerComboBox(
                {
                    onSelected: function (value, text) {
                        if (value == -1) {
                            $("#txtAuditContent").val("不同意");
                        }
                        else {
                            $("#txtAuditContent").val("同意 " + text);
                        }
                    }
                });

            $("form").ligerForm();
        });
    </script>
}
<div style="overflow-x: hidden; overflow-y: auto; height: 100%">
    <input type="hidden" name="projectID" id="projectID" value="@project.ID" />
    <form name="formaudit" method="post" id="formaudit">
    <table cellpadding="0" cellspacing="0" class="tablel" width="100%">
        <tr>
            <td align="right" width="80">
                当前工作:
            </td>
            <td align="left" width="200">
                @processDoing.ProcessName
            </td>
            <td align="right" width="80">
                我的审核:
            </td>
            <td align="left" width="200">
                <select id="selProcessStep">
                    @{
                        string signcontent = "";
                        if (processStepList != null && processStepList.Count > 0)
                        {
                            signcontent = "同意 " + processStepList[0].StepName;
                            foreach (var item in processStepList)
                            {
                        <option value="@item.ID">@item.StepName</option>
                            }
                        }
                    }
                    <option value="-1">审核不通过</option>
                </select>
            </td>
            <td align="right" width="80">
                审核人:
            </td>
            <td align="left">
                @processDoing.User.RealName
            </td>
        </tr>
        <tr>
            <td align="right">
                审核意见:
            </td>
            <td align="left" colspan="7">
                <textarea rows="3" class="l-textarea" style="width: 740px" id="txtAuditContent">@signcontent</textarea>
            </td>
        </tr>
        <tr>
            <td align="right">
            </td>
            <td align="left" colspan="7">
                <input type="button" value="提交" id="btnSave" class="l-button" />&nbsp;&nbsp;<input
                    type="button" value="取消" id="btnCancel" class="l-button" />
            </td>
        </tr>
    </table>
    </form>
    <div id="projecttab" style="padding-top: 10px">
        <div tabid="projectbase" title="项目信息" lselected="true">
            <div style="width: 100%">
                <table cellpadding="0" cellspacing="0" class="tablel" width="100%">
                    <tr>
                        <td align="right" width="9%">
                            产品名称:
                        </td>
                        <td align="left" width="16%">
                            <span style="color: #000079; font-size: 16px;">
                                @project.ProductName
                            </span>
                        </td>
                        <td align="right" width="9%">
                            项目名称:
                        </td>
                        <td align="left" width="16%">
                            <span style="color: #000079; font-size: 16px;">
                                @project.ProjectTitle
                            </span>
                        </td>
                        <td align="right" width="9%">
                            项目代码:
                        </td>
                        <td align="left" width="16%">
                            <span style="color: #000079; font-size: 16px;">
                                @project.ProjectCode
                            </span>
                        </td>
                        <td align="right" width="9%">
                            投资开放时间:
                        </td>
                        <td align="left" width="16%">
                            <span style="color: #000079; font-size: 16px;">
                                @project.WaitDay 天</span>
                        </td>
                    </tr>
                    <tr>
                        <td align="right">
                            融资金额:
                        </td>
                        <td align="left">
                            <span style="color: #000079; font-size: 16px;">
                                @(Math.Round(project.Financing / 10000, 2, MidpointRounding.AwayFromZero))
                            </span>万元
                        </td>
                        <td align="right">
                            投资起点金额:
                        </td>
                        <td align="left">
                            <span style="color: #000079; font-size: 16px;">
                                @project.MinInvestment.ToString("F2")</span>元
                        </td>
                        <td align="right">
                            递增单位金额:
                        </td>
                        <td align="left">
                            <span style="color: #000079; font-size: 16px;">
                                @project.IncreaseMoney.ToString("F2")</span>元
                        </td>
                        <td align="right">
                            借款时间:
                        </td>
                        <td align="left">
                            <span style="color: #000079; font-size: 16px;">
                                @(project.CycleAmount * project.PolicyList.FirstOrDefault(c => !c.IsAttach).Duration)@(project.PolicyList.FirstOrDefault(c => !c.IsAttach).DurationType.Mapping())</span>
                            （@project.CycleAmount 期 * @project.PolicyList.FirstOrDefault(c => !c.IsAttach).Duration
                            @project.PolicyList.FirstOrDefault(c => !c.IsAttach).DurationType.Mapping() /期）
                        </td>
                    </tr>
                    <tr>
                        <td align="right">
                            结算方式:
                        </td>
                        <td align="left">
                            <span style="color: #000079; font-size: 16px;">
                                @policy.BalanceType.Mapping()</span>
                        </td>
                        <td align="right">
                            结算周期:
                        </td>
                        <td align="left">
                            <span style="color: #000079; font-size: 16px;">
                                @policy.Duration
                                @(policy.DurationType.Mapping())</span>
                        </td>
                        <td align="right">
                            创建人:
                        </td>
                        <td align="left">
                            <span style="color: #000079; font-size: 16px;">
                                @project.User.RealName</span>
                        </td>
                        <td align="right">
                            创建时间:
                        </td>
                        <td align="left">
                            <span style="color: #000079; font-size: 16px;">
                                @project.CreateTime.ToString("yyyy-MM-dd HH:mm:ss")</span>
                        </td>
                    </tr>
                    <tr>
                        <td align="right">
                            借款年化利率:
                        </td>
                        <td align="left">
                            <span style="color: Red; font-size: 16px;">@(project.OriginalRate)%</span>
                        </td>
                        <td align="right">
                            借款总利息:
                        </td>
                        <td align="left">
                            <span style="color: Red; font-size: 16px;">@Math.Round((project.Financing * project.OriginalRate / 100) * (monthcount / 12), 2, MidpointRounding.AwayFromZero)</span>元
                        </td>
                        <td align="right" rowspan="3">
                            额外奖励:
                        </td>
                        <td align="left" colspan="3" rowspan="3">
                            @{
                                
                                if (project.PolicyList != null && project.PolicyList.Count > 0)
                                {

                                    var attachPolicys = project.PolicyList.Where(c => c.IsAttach).ToList();

                                    if (attachPolicys != null && attachPolicys.Count > 0)
                                    {

                                <ul>
                                    @{
                                         
                                        foreach (var item in attachPolicys)
                                        {
                                         int duration = item.Duration;
                                            DurationType durationType = item.DurationType;
                                            if(duration==0)
                                            {
                                                duration = policy.Duration;
                                                durationType = policy.DurationType;
                                            }
                                            
                                        <li><strong style="color: Red;">额外追加 @item.Rate @(item.SettlementType == SettlementType.Proportion ? "% 年化收益率" : "元固定收益")
                                            (@(item.CycleAmount == 0 ? project.CycleAmount : item.CycleAmount)期*@duration@durationType.Mapping()/期)</strong></li>
                                            

                                        }
                                         
                                    }
                                </ul>
                                    }
                                    else
                                    {
                                <span style="color: Red; font-size: 16px;">无 </span>
                                    }

                                }
                            }
                        </td>
                    </tr>
                    <tr>
                        <td align="right">
                            投资年化利率:
                        </td>
                        <td align="left">
                            <span style="color: Red; font-size: 16px;">
                                @(policy.Rate)% </span>
                        </td>
                        <td align="right">
                            投资总收益:
                        </td>
                        <td align="left">
                            <span style="color: Red; font-size: 16px;">
                                @Math.Round((project.Financing * policy.Rate / 100) * (monthcount / 12), 2, MidpointRounding.AwayFromZero)
                            </span>元
                        </td>
                    </tr>
                    <tr>
                        <td align="right">
                            担保金年化利率:
                        </td>
                        <td align="left">
                            <span style="color: Red; font-size: 16px;">
                                @(project.GuaranteeRate)%</span>
                        </td>
                        <td align="right">
                            担保金:
                        </td>
                        <td align="left">
                            <span style="color: Red; font-size: 16px;">@Math.Round((project.Financing * project.GuaranteeRate / 100) * (monthcount / 12), 2, MidpointRounding.AwayFromZero)</span>元
                        </td>
                    </tr>
                    <tr>
                        <td align="right">
                            平台收益率:
                        </td>
                        <td align="left">
                            <span style="color: #000079; font-weight: bold; font-size: 17px;">
                                @(project.OriginalRate - policy.Rate - project.GuaranteeRate)%</span>
                        </td>
                        <td align="right">
                            平台收益金额:
                        </td>
                        <td align="left">
                            <span style="color: #000079; font-weight: bold; font-size: 17px;">@profits.ToString("F2")</span>元
                        </td>
                        <td align="right">
                            奖励金额:
                        </td>
                        <td align="left">
                            <span style="color: #000079; font-weight: bold; font-size: 17px;">
                                @reward.ToString("F2")</span>
                        </td>
                        <td align="right">
                            平台最终收益:
                        </td>
                        <td align="left">
                            <span style="color: #000079; font-weight: bold; font-size: 17px;">
                                @lastprofits.ToString("F2")</span>元
                        </td>
                    </tr>
                    <tr>
                        <td align="right">
                            担保公司:
                        </td>
                        <td align="left">
                            <span style="color: #000079; font-size: 16px;">
                                @project.GuaranteeCompany.CompanyName</span>
                        </td>
                        <td align="right">
                            担保意见:
                        </td>
                        <td align="left" colspan="5">
                            @project.CollateralOpinion
                        </td>
                    </tr>
                    <tr>
                        <td align="right">
                            风险控制:
                        </td>
                        <td align="left" colspan="7">
                            @project.RiskCotrolSummary
                        </td>
                    </tr>
                    <tr>
                        <td align="right">
                            项目描述:
                        </td>
                        <td align="left" colspan="7">
                            @project.ProjectDescription
                        </td>
                    </tr>
                </table>
            </div>
        </div>
        <div title="借款企业">
            <div style="width: 100%">
                <table cellpadding="0" cellspacing="0" class="tablel" width="100%">
                    <tr>
                        <td align="right" width="9%">
                            企业名称:
                        </td>
                        <td align="left" width="33%">
                            <span style="color: #000079; font-size: 16px;">
                                @project.Enterprise.EnterpriseName
                            </span>
                        </td>
                        <td align="right" width="9%">
                            企业代码:
                        </td>
                        <td align="left" width="20%">
                            <span style="color: #000079; font-size: 16px;">
                                @project.Enterprise.EnterpriseCode
                            </span>
                        </td>
                        <td align="right" width="9%">
                            企业信用:
                        </td>
                        <td align="left" width="20%">
                            <span style="color: #000079; font-size: 16px;">
                                @project.Enterprise.EnterpriseCredit
                            </span>
                        </td>
                    </tr>
                    <tr>
                        <td align="right">
                            企业信息:
                        </td>
                        <td align="left" colspan="7">
                            @project.Enterprise.EnterpriceInfo
                        </td>
                    </tr>
                    <tr>
                        <td align="right">
                            资金用途:
                        </td>
                        <td align="left" colspan="7">
                            @project.Enterprise.CapitalOperation
                        </td>
                    </tr>
                </table>
            </div>
        </div>
        <div title="相关资料">
            <table cellpadding="0" cellspacing="0" class="tablel" width="100%">
            @{
                if(project.ResourceList!=null&&project.ResourceList.Count>0)
                {
                    var resourceListTemp = project.ResourceList.GroupBy(c => c.SubType).ToList();
                    foreach(var item in resourceListTemp)
                    {
                        string resourceType = item.Key.Mapping();
                        var resources = project.ResourceList.Where(c => c.SubType == item.Key).ToList();
                        <tr style="font-size: 14px; font-weight: bold; color: #000079;">
                        <td colspan="5">@resourceType</td>
                        </tr>
                        <tr>
                        <td>
                        @if(resources!=null&&resources.Count>0)
                        {
                            string imageExtend=".jpg|.bmp|.gif|.png|.jpeg";
                            foreach(var res in resources)
                            {
                                if(imageExtend.Contains(res.ExtendName.ToLower()))
                                {
                                    <img width="173" height="98" src="@res.Path"/>
                                }
                                else
                                {
                                    <a href="@res.Path">@res.Name</a>
                                }
                            }
                        }
                        </td>
                        </tr>
                    }
                }
            } 
            </table>
        </div>
        <div title="还款计划">
            @{
                if (repaymentPlanList != null && repaymentPlanList.Count > 0)
                {
                    foreach (var item in repaymentPlanList)
                    {
                        string policyStr = "";
                        if (item.Policy.IsAttach)
                        {
                            policyStr = "平台奖励";
                        }
                   
                        
                <div style="margin: 10px;">
                    <span style="color: Red; font-size: 16px;">
                        @policyStr @item.Policy.Rate @(item.Policy.SettlementType == SettlementType.Proportion ? "% 年化收益率" : "元固定收益")</span>
                    (@(item.Policy.CycleAmount == 0 ? project.CycleAmount : item.Policy.CycleAmount)期*@item.Policy.Duration@item.Policy.DurationType.Mapping()/期)<span
                        style="color: #000079; font-size: 16px;">
                        @item.Policy.BalanceType.Mapping()</span>的还款计划
                    <table cellpadding="0" cellspacing="0" class="tablel" width="100%">
                        <tr style="font-size: 14px; font-weight: bold; color: #000079;">
                            <td align="center" width="10%">
                                期数
                            </td>
                            <td align="center" width="15%">
                                需还本金(￥)
                            </td>
                            <td align="center" width="15%">
                                需还利息(￥)
                            </td>
                            <td align="center" width="15%">
                                需还本息和(￥)
                            </td>
                            <td align="center" width="15%">
                                待还本金(￥)
                            </td>
                            <td align="center" width="15%">
                                待还利息(￥)
                            </td>
                            <td align="center" width="15%">
                                待还本息和(￥)
                            </td>
                        </tr>
                        @if (item.RepaymentPlanItemList != null && item.RepaymentPlanItemList.Count > 0)
                        {
                            <tr style="font-size: 13px; font-weight: bold; color: #e86e00;">
                                <td align="center">
                                </td>
                                <td align="center">
                                </td>
                                <td align="center">
                                </td>
                                <td align="center">
                                </td>
                                <td align="center">
                                    @(item.RepaymentPrincipal)
                                </td>
                                <td align="center">
                                    @(item.RepaymentInterest)
                                </td>
                                <td align="center">
                                    @(item.RepaymentPrincipal + item.RepaymentInterest)
                                </td>
                            </tr>
                            foreach (var planItem in item.RepaymentPlanItemList)
                            {
                            <tr style="font-size: 12px; color: #000079;">
                                <td align="center">
                                    @planItem.CycleNumber
                                </td>
                                <td align="center">
                                    @planItem.RepaymentPrincipal
                                </td>
                                <td align="center">
                                    @planItem.RepaymentInterest
                                </td>
                                <td align="center">
                                    @(planItem.RepaymentPrincipal + planItem.RepaymentInterest)
                                </td>
                                <td align="center">
                                    @planItem.ReMainPrincipal
                                </td>
                                <td align="center">
                                    @planItem.ReMainInterest
                                </td>
                                <td align="center">
                                    @(planItem.ReMainPrincipal + planItem.ReMainInterest)
                                </td>
                            </tr>
                            }
                        }
                    </table>
                </div>
                    }
                }
            }
        </div>
        <div title="审核记录" id="divAuditHistory" style="overflow: auto;" class="l-scroll;">
            <table cellpadding="0" cellspacing="0" class="tablel" width="100%">
                <tr style="font-size: 14px; font-weight: bold; color: #000079;">
                    <td align="center" width="20%">
                        当前工作
                    </td>
                    <td align="center" width="10%">
                        办理状态
                    </td>
                    <td align="center">
                        办理意见
                    </td>
                    <td align="center" width="10%">
                        办理人
                    </td>
                    <td align="center" width="20%">
                        办理时间
                    </td>
                </tr>
                @{
                    if (processDoingHistoryList != null && processDoingHistoryList.Count > 0)
                    {
                        foreach (var item in processDoingHistoryList)
                        {
                            string doState = "审核通过";
                            if (item.DoDirection == -1)
                            {
                                doState = "审核不通过";
                            }
                    <tr>
                        <td>@item.ProcessDoing.ProcessName
                        </td>
                        <td align="center">@doState
                        </td>
                        <td>@item.DoingContent
                        </td>
                        <td align="center">@item.User.RealName
                        </td>
                        <td align="center">@item.DoingTime.ToString("yyyy-MM-dd HH:mm:ss")
                        </td>
                    </tr>
                        }
                    }
                }
            </table>
        </div>
    </div>
</div>
